
extends Control


@onready var menu_items: Array = [
	$MenuCR/VBox/Local,
	$MenuCR/VBox/Net,
	$MenuCR/VBox/Setting,
	$MenuCR/VBox/Quit
]

# 光标与当前的项
var pointer: int = 0
var current_item: TemplateSelectItem = null




func _ready() -> void:
	# 向 Android 用户申请权限
	# 目前不需要任何权限
	#OS.request_permissions()
	# 初始化当前的项
	# 选中第一个
	current_item = menu_items[pointer]
	current_item.set_select(true)




func _input(_event: InputEvent) -> void:
	# 阻止输入事件继续传播
	get_viewport().set_input_as_handled()
	
	if _event.is_action_pressed("pointer_down"):
		if pointer + 1 < menu_items.size():
			pointer += 1
			current_item.set_select(false)
			current_item = menu_items[pointer]
			current_item.set_select(true)
	
	elif _event.is_action_pressed("pointer_up"):
		if pointer - 1 > -1:
			pointer -= 1
			current_item.set_select(false)
			current_item = menu_items[pointer]
			current_item.set_select(true)
	
	# 确认
	elif _event.is_action_pressed("action_confirm"):
		action_confirm()




## 确认处理
func action_confirm() -> void:
	# 根据当前项的文本来决定进行哪个
	match current_item.get_info_text():
		"本地":
			confirm_local()
		"网络":
			confirm_net()
		"设置":
			confirm_setting()
		"退出":
			confirm_quit()




## 进入本地模式
func confirm_local() -> void:
	get_tree().change_scene_to_file("res://game/local/level/level_zero/level_zero.tscn")




## 进入联网模式
func confirm_net() -> void:
	get_tree().change_scene_to_file("res://src/net/net_info.tscn")




## 进入设置
func confirm_setting() -> void:
	pass




func confirm_quit() -> void:
	get_tree().quit()
